const template = require('art-template');
const dayjs = require('dayjs');
const { workerData, parentPort } = require('worker_threads');

const mailer = require('../lib/mailer');
const ART_TEMPLATE_CONF = require('../conf/art-template');

Object.assign(template.defaults, ART_TEMPLATE_CONF);

(async function () {
  // template
  const { email, content, remindTime } = workerData;

  const time = dayjs(remindTime).format('YYYY-MM-DD HH:mm');
  const html = template('remind', { email, content, time });
  const mailOptions = {
    from: mailer.sender,
    to: email,
    subject: 'todo2024-任务提醒',
    // 为了接收邮箱识别验证码邮件，发送内容从简
    html
  };
  await mailer.send(mailOptions);
  parentPort.postMessage('remind successfully');
})();
